﻿<!DOCTYPE html>
<html>
<head>
    <title>APPLIST</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/ViewV5/CSS/icfont_qj/iconfont.css">
    <link rel="stylesheet" type="text/css" href="/ViewV5/CSS/animate.css">
    <link rel="stylesheet" type="text/css" href="/ViewV5/CSS/bootstrap3.3.5/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/ViewV5/CSS/default.css">
    <link rel="stylesheet" type="text/css" href="/ViewV5/CSS/index.css">

</head>
<body ms-controller="appview">

    <div style="min-height:650px;">

        <div ms-include-src="'/ViewV5/AppPage/'+PathCode+'/'+FormCode+'LIST.html?r='+Math.random()" data-include-rendered='render'>
        </div>
        <div ms-if="Total>0" class="ui-datatable-page" id="pageDiv">
        </div>

    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close default"
                            data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        自定义显示列
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="fun-box-tj"><span class="tj-border-left"></span>选择显示列:</div>
                    <div class="modal-tj">

                        <ul class="list-unstyled fun-box crm-kh-px">
                            <li ms-repeat-el="ShowColumns">
                                <div class="fun-list-cont" ms-class-1="active:el.IsSel" ms-click="ReSetShow(el)">
                                    <span>{{el.ColText}}</span>
                                </div>
                            </li>
                        </ul>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">
                        关闭
                    </button>
                    <!-- <button type="button" class="btn btn-primary">
                       提交更改
                    </button>-->
                </div>
            </div>
        </div>
    </div>

    <script src="../JS/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="../JS/laypage/laypage.js"></script>
    <script src="../JS/avalon.js"></script>
    <script src="../JS/SZHLCommon.js?jsver=20170915"></script>

    <script type="text/javascript">
        //$(".crm-tab .fa").check(function(){
        //	$(this).addClass("fa-check-square")
        //})
        var model = avalon.define({
            $id: "appview",
            userName: ComFunJS.getnowuser(),
            PathCode: "",
            FormCode: ComFunJS.getQueryString("FormCode"),
            search: { seartype: "1", searchcontent: "" },
            TypeData: {},
            GetTypeData: function (P1, callback) {//P1:参数类别，callback:回调函数
                $.getJSON('/API/VIEWAPI.ashx?Action=XTGL_GETZIDIANLIST', { P1: P1 }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        return callback.call(this, resultData.Result);
                    }
                })
            },
            SelectType: function (type) {
                model.search.seartype = type;
                tempindex.GetLIST();
            },
            lbtype: "",
            SelectType2: function (type) {
                model.lbtype = type;
                tempindex.GetLIST();
            },
            TypeData1: [],
            ShowColumns: [],  //显示的列名，数据在模板中填充
            TempColumns: [],
            page: "1",
            Total: 0,
            CommonData: [], //列表数据
            render: function () {
                if (tempindex) {
                    tempindex.InitWigetData();
                    //model.TempColumns = model.ShowColumns;
                    //model.ShowColumns.clear();
                    if (model.ShowColumns.size() > 0) {
                        setTimeout("model.GetExtColumns()", 1500);
                    }
                }
                avalon.templateCache = null;
            },
            GetExtColumns: function () {

                $.getJSON('/API/VIEWAPI.ashx?Action=XTGL_GETEXTENDFIELD', { P1: model.FormCode }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        $(resultData.Result).each(function (idx, itm) {
                            model.ShowColumns.push({ ColName: itm.TableFiledName, ColText: itm.TableFiledName, IsSel: false, format: model.fnDefault });
                        })

                        var ext = localStorage.getItem(model.FormCode + "ShowColumns");
                        if (ext) {
                            $(model.ShowColumns).each(function (idx, itm) {
                                $(JSON.parse(ext)).each(function (index, ele) {
                                    if (itm.ColName == ele.ColName) {
                                        itm.IsSel = ele.IsSel;
                                    }
                                })
                            })

                        }
                        //model.ShowColumns = model.TempColumns;
                    }
                })
            },
            Add: function (FormCode) {
                top.ComFunJS.winviewform("/ViewV5/AppPage/APP_ADD_WF.html?vsr=2017&FormCode=" + FormCode, '添加表单', "1000", "");
            },
            View: function (ID, PIID) {
                top.ComFunJS.winviewformright2("/ViewV5/AppPage/APPView.html?vsr=2017&FormCode=" + model.PathCode + "_" + model.FormCode + "&ID=" + ID + "&PIID=" + PIID + "&r=" + Math.random(), '详细信息', "1000", "");
            },
            ViewForm: function (ID, PIID, event) {
                if (event.stopPropagation) {
                    event.stopPropagation();
                }
                top.ComFunJS.winviewform("/ViewV5/AppPage/APP_ADD_WF.html?vsr=2017&FormCode=" + model.PathCode + "_" + model.FormCode + "&ID=" + ID + "&PIID=" + PIID, "修改表单", "1000", "");
            },
            ReSetShow: function (el) {
                if (el) {
                    if (el.IsSel == true) {
                        el.IsSel = false;
                    } else {
                        el.IsSel = true;
                    }
                    localStorage.setItem(model.FormCode + "ShowColumns", JSON.stringify(model.ShowColumns));
                }
            },

            //格式化
            fnDefault: function (str) {
                return str;
            },
            //审核状态
            fnSHState: function (str) {
                if (str == 0) {
                    return "未审核";
                } else if (str == -1) {
                    return "审核不通过";
                } else if (str == 1) {
                    return "审核通过";
                } else
                    return "";
            },
            fnStateName: function (str) { if (str == "-1") return ""; return str; },
            fnDateFormat: function (str) {
                if (str) {
                    return ComFunJS.getnowdate("yyyy-mm-dd", str);
                }
                return str;
            },
            fnUserName: function (str) {
                if (str) {
                    return ComFunJS.convertuser(str);
                }
                return str;
            },
            fnQrCode: function (str) {
                if (str) {
                    return "<img src='" + str + "' style='width:60px;height:60px;' />"
                }
                return str;
            },
            fnBQH: function (str) {
                if (str) {
                    return ComFunJS.bqhContent(str);
                }
                return str;
            }, covText: function (text, len) {
                return ComFunJS.convstr($("<div>" + text + "</div>").text(), len || 20);
            }

        })

        avalon.ready(function () {
            if (model.FormCode.indexOf("_") > 0) {
                model.PathCode = model.FormCode.split('_')[0];
                model.FormCode = model.FormCode.split('_')[1];
            } else {
                model.PathCode = model.FormCode;
            }

            avalon.filters.fnFormat = function (str, format) {
               
                return str + "A";
            }
        })
    </script>
</body>
</html>